package com.csthink.mysql.repository;

import com.csthink.mysql.constant.DbConstant;
import com.csthink.mysql.entity.WebPermission;
import com.csthink.mysql.mapper.WebPermissionMapper;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;

/**
 * 注意: 请勿继承mybatis-plus 的 ServiceImpl以及 BaseMapper 类
 * 一旦 Service 类或者 Repository 类继承了 Mybatis-Plus 的 ServiceImpl 类，
 * 这将导致可以绕过 Repository 类直接使用 ServiceImpl 提供的 DB 操作方法，
 * 非常有可能在应当对缓存进行清除的时候没有清除
 *
 * @author <a href="mailto:security.2009@live.cn">Mars</a>
 * @since 2023-09-11
 */
@CacheConfig(cacheNames = {DbConstant.TABLE_WEB_PERMISSION_NAME_KEY_FORMAT})
@Repository
public class WebPermissionRepository {

    @Setter(onMethod_ = @Autowired)
    private WebPermissionMapper webPermissionMapper;


    @Cacheable(key = "{#p0}")
//    @Cacheable(
//            key = "{#p0}",
//            condition="@cacheAspect.isConditionPassing(T(com.csthink.mysql.constant.DbConstant).TABLE_WEB_PERMISSION_NAME)")
    public WebPermission getByPermissionId(String id) {
        WebPermission webPermission = webPermissionMapper.selectById(id);
        return webPermission;
    }

    public void deletePermissionById(String id) {

    }
}
